﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class MobileLogin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (CheckCredentials(TextBox1.Text, TextBox2.Text))
        {
            Session["orderitemsmain"] = new OrderItemsMain();

            Response.Redirect("MobileOrderLanding.aspx");
        }
        else
        {
            Response.Redirect("MobileLoginFailure.aspx");
        }
    }

    private bool CheckCredentials(string UserName, string Password)
    {
        bool authenticated = false;

        string strConnection = "Data Source=csd.columbusstate.edu;Initial Catalog=6118_fa12_TeamC;User ID=student;Password=cscpsc12";

        SqlConnection connection = new SqlConnection(strConnection);

        String query = "SELECT * FROM CUSTOMER";

        SqlCommand command = new SqlCommand(query, connection);

        SqlDataReader reader;

        connection.Open();

        reader = command.ExecuteReader();

        while (reader.Read())
        {
            if ((UserName == reader["UNAME"].ToString()) && (Password == reader["PWD"].ToString()))
            {
                CUSTOMER c = new CUSTOMER();

                c.CID = Convert.ToInt32(reader["CID"].ToString());
                c.UNAME = reader["UNAME"].ToString();
                c.FNAME = reader["FNAME"].ToString();
                c.LNAME = reader["LNAME"].ToString();
                c.ADDR = reader["ADDR"].ToString();
                c.CITY = reader["CITY"].ToString();
                c.STATE = reader["STATE"].ToString();
                c.ZIP = reader["ZIP"].ToString();

                Session["customer"] = c;

                authenticated = true;

                reader.Close();

                return authenticated;
            }
        }

        reader.Close();
        return authenticated;
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
}
